package com.hl.vcd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hl.vcd.entity.CollectionRecords;
import com.hl.vcd.entity.vo.CollectionRecordsDetail;
import com.hl.vcd.mapper.CollectionRecordsMapper;
import com.hl.vcd.service.CollectionRecordsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 朱炫达
 */
@Service
@Transactional
public class CollectionRecordsServiceImpl extends ServiceImpl<CollectionRecordsMapper, CollectionRecords> implements CollectionRecordsService {
    @Override
    public void addCollectionRecords(CollectionRecords collectionRecords) {
        baseMapper.insert(collectionRecords);
    }

    @Override
    public void deleteCollectionRecordsByUserIdAndVideoId(String userId,String videoId) {
        QueryWrapper<CollectionRecords> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        wrapper.eq("video_id",videoId);
        baseMapper.delete(wrapper);
    }

    @Override
    public IPage<CollectionRecordsDetail> getCollectionRecordsDetailByUserId(Page<CollectionRecordsDetail> page,String userId) {
        return baseMapper.getCollectionRecordsDetailByUserId(page,userId);
    }

    @Override
    public CollectionRecords getCollectionRecordsByUserIdAndVideoId(String userId, String videoId) {
        QueryWrapper<CollectionRecords> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        wrapper.eq("video_id",videoId);
        return baseMapper.selectOne(wrapper);
    }
}
